package com.abl.controller.system;

import com.abl.common.security.annotation.ResC;
import com.abl.common.security.annotation.ResM;
import com.abl.domain.dto.system.UserAddDTO;
import com.abl.domain.model.Param;
import com.abl.domain.model.SRS;
import com.abl.controller.BaseController;
import com.abl.service.system.SysPostService;
import com.abl.service.system.SysRoleService;
import com.abl.service.system.SysUserService;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@ResC("用户管理")
@Tag(name = "用户管理")
@RestController
@RequestMapping("/system/user")
public class SysUserController extends BaseController {
    @Autowired
    private SysUserService service;

    @Autowired
    private SysRoleService roleService;

    @Autowired
    private SysPostService postService;


    @ResM(value = "系统登录", login = "1")
    @PostMapping({"/login"})
    public SRS<Object> login(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.login(param));
    }

    @ResM("退出登录")
    @PostMapping({"/logout"})
    public SRS<Object> logout(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.logout(param));
    }

    /**
     * 添加用户
     *
     * @apiNote 添加用户
     */
    @ResM("添加用户")
    @PostMapping(value = {"/add"})
    public SRS<Object> add(@RequestBody UserAddDTO param) {
        return SRS.bySuccess(service.add(param));
    }


    @ResM("删除用户")
    @PostMapping({"/del"})
    public SRS<Object> del(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.del(param));
    }

    @ResM("重置密码")
    @PostMapping({"/resetPassword"})
    public SRS<Object> resetPassword(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.resetPassword(param));
    }

    @ResM("修改用户信息、账号信息")
    @PostMapping({"/edit"})
    public SRS<Object> edit(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.edit(param));
    }


    @ResM("账号详情")
    @PostMapping("/loginUserInfo")
    public SRS<Object> loginUserInfo(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.loginUserInfo(param));
    }

    @ResM("查询集合")
    @PostMapping({"/list"})
    public SRS<Object> list(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.list(param));
    }

    @ResM("刷新Token")
    @PostMapping("/refreshToken")
    public SRS<Object> refreshToken(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.refreshToken(param));
    }

    @ResM("用户菜单")
    @PostMapping("/menu")
    public SRS<Object> menu(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(service.menu(param));
    }


    @ResM("职位下拉列表")
    @PostMapping("/postList")
    public SRS<Object> postList(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(postService.list(param));
    }

    @ResM("角色下拉列表")
    @PostMapping({"/roleList"})
    public SRS<Object> roleList(@RequestBody Param<JSONObject> param) {
        return SRS.bySuccess(roleService.list(param));
    }
}
